package com.wd.tech.Base;

import com.wd.tech.contracts.Contract;

import java.lang.ref.WeakReference;

/**
 * date:2020/7/2
 * author:王成虎(13671)
 * month:七月
 * function:
 */
public abstract class BasePresenter <V extends Contract.IView> implements Contract.IPresenter  {

    //弱引用
    protected WeakReference<V> mReference;
    //构造函数
    public BasePresenter() {
        //初始化model层
        initModel();
    }
    //绑定
    protected void  onBulde(V v){
        mReference = new WeakReference<>(v);
    }
    //解绑
    protected void  onDetry(){
        if (mReference!=null){
            mReference.clear();
            mReference=null;
        }
    }
    //getview
    public V getView(){
        return mReference.get();
    }

    protected abstract void initModel();

}
